document.write('<script src="static/js/ajaxfileupload.js"' + '></' + 'script>')
document.write('<style type="text/css" >.up_list {float: left;margin-left: 0.3rem;}.j-list {position: relative;width: 180px;height: 120px;display: inline-block;font-size: 12px;color: #999;text-align: center;line-height: 80px;margin-right: 10px;}.j-del {position: absolute;width: 20px;height: 20px;color: #000;line-height: 20px;text-align: center;color: #fff;right: -10px;top: -10px;cursor: pointer;border-radius: 10px;background: rgba(0, 0, 0, .5);}</style>')
/**
 * 图片上传
 * @author YeWJ <891718689@qq.com>
 * @param imgID: 文件框id
 * @param name: 图片路径框name属性名
 * @param num: 允许上传的图片数
 * @return void|bool
 */
function image_upload(imgID, name, num){
    if(!isNaN(num)) num = 1;

    if (countUpImgLen() >= num) {
        return false;
    }

    $.ajaxFileUpload({
        type: "post",
        fileElementId:imgID,
        url: "?ct=upload&ac=upload_img&img_id="+imgID,
        dataType: 'json',
        success: function (data) {
            if(data.error == 0){
                var html = '<div class="j-list up_list"><span class="j-del">X</span>' +
                    '<input type="hidden" value="'+ data.filename +'" readonly="readonly" name="'+name+'">' +
                    '<img alt="" src="' + data.url +'" width="180" height="120"> </div>';
                $('#'+imgID).before(html);
            }else{
                alert(data.msg);
            }
        }
    });
}

/*删除图片*/
$("body").on("click", ".j-del", function () {
    $(this).parents(".up_list").remove();
    if (countUpImgLen() < 2) {
        $("#picker").show();
    }
});

function countUpImgLen() {
    return $(".up_list").length;
}